<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >

<mapper namespace="${packagename}.mapper.${table.classname}Mapper">

	<sql id="sqlbase">
		A.${table.pkname} as ${table.pkjavaname},
<#list columnlist as column>
	<#if column_has_next>
		A.${column.columnjdbcname} as ${column.columnjavaname},
	</#if>
	<#if !column_has_next>
		A.${column.columnjdbcname} as ${column.columnjavaname}
	</#if>
</#list>
	</sql>

	<insert id="insert" parameterType="${table.classname}" useGeneratedKeys="true" keyProperty="${table.pkjavaname}">
		insert into ${table.tableallname}
		<trim prefix="(" suffix=")" suffixOverrides=",">
<#list columnlist as column>
	<#if column.columnjavaname != "updateTime" && column.columnjavaname != "createTime">
			<if test="${column.columnjavaname} != null">${column.columnjdbcname},</if>
	</#if>
</#list>
		</trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
<#list columnlist as column>
	<#if column.columnjavaname != "updateTime" && column.columnjavaname != "createTime">
			<if test="${column.columnjavaname} != null">${r'#{'}${column.columnjavaname}${r'}'},</if>
	</#if>
</#list>
		</trim>
	</insert>

	<update id="update" parameterType="${table.classname}">
		update ${table.tableallname}
		<set>
			<trim suffixOverrides=",">
<#list columnlist as column>
	<#if column.columnjavaname != "updateTime" && column.columnjavaname != "createTime">
				<if test="${column.columnjavaname} != null">${column.columnjdbcname} = ${r'#{'}${column.columnjavaname}${r'}'},</if>
	</#if>
</#list>
			</trim>
		</set>
		where ${table.pkname} = ${r'#{'}${table.pkjavaname}${r'}'} <if test="updateTime != null">and update_time = ${r'#{'}updateTime${r'}'}</if>
	</update>

	<select id="get" parameterType="Long" resultType="${table.classname}">
		select
		<include refid="sqlbase" />
		from ${table.tableallname} A
		where A.${table.pkname} = ${r'#{'}${table.pkjavaname}${r'}'}
	</select>

	<select id="count" resultType="Integer">
		select count(1)
		from ${table.tableallname} A
		${r'${sqlConf}'}
	</select>

	<select id="search" resultType="${table.classname}">
		select
		${r'${field}'}
		from ${table.tableallname} A
		${r'${sqlConf}'}
		${r'${orderBy}'}
	</select>

	<update id="deleteFalse">
		update ${table.tableallname}
		set status = 0
		where ${table.pkname} = ${r'#{'}${table.pkjavaname}${r'}'}
	</update>

	<delete id="deleteTrue">
		delete from ${table.tableallname}
		where ${table.pkname} = ${r'#{'}${table.pkjavaname}${r'}'}
	</delete>

</mapper>